--DO NOT MODIFY THIS FILE. IT IS ALWAYS OVERWRITTEN ON GENERATION.
--Data Schema For Version 0.0.0.0
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[gen_AllTypesDelete]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [dbo].[gen_AllTypesDelete]
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

CREATE PROCEDURE [dbo].[gen_AllTypesDelete]
(
	@Original_all_type_id UniqueIdentifier
)
AS
SET NOCOUNT OFF;

DELETE FROM 
	[ALL_TYPES] 
WHERE 
	[all_type_id] = @Original_all_type_id ;

GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[gen_AllTypesSelectByAllTypesPks]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [dbo].[gen_AllTypesSelectByAllTypesPks]
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO


CREATE PROCEDURE [dbo].[gen_AllTypesSelectByAllTypesPks]
(
	@xml ntext
)
AS

DECLARE @hDoc int
EXEC sp_xml_preparedocument @hDoc OUTPUT, @xml

SELECT
		[ALL_TYPES].[xml],
	[ALL_TYPES].[varcharmax],
	[ALL_TYPES].[varchar],
	[ALL_TYPES].[varbinarymax],
	[ALL_TYPES].[varbinary],
	[ALL_TYPES].[uniqueidentifier],
	[ALL_TYPES].[tinyint],
	[ALL_TYPES].[time],
	[ALL_TYPES].[text],
	[ALL_TYPES].[sql_variant],
	[ALL_TYPES].[smallmoney],
	[ALL_TYPES].[smallint],
	[ALL_TYPES].[smalldatetime],
	[ALL_TYPES].[real],
	[ALL_TYPES].[nvarcharmax],
	[ALL_TYPES].[nvarchar],
	[ALL_TYPES].[numeric],
	[ALL_TYPES].[ntext],
	[ALL_TYPES].[nchar],
	[ALL_TYPES].[money],
	[ALL_TYPES].[int_test],
	[ALL_TYPES].[image],
	[ALL_TYPES].[hierarchyid],
	[ALL_TYPES].[geometry],
	[ALL_TYPES].[geography],
	[ALL_TYPES].[float_test],
	[ALL_TYPES].[decimal_test],
	[ALL_TYPES].[datetimeoffset],
	[ALL_TYPES].[datetime2],
	[ALL_TYPES].[datetime],
	[ALL_TYPES].[date_test],
	[ALL_TYPES].[computedpersisted],
	[ALL_TYPES].[computednotpersisted],
	[ALL_TYPES].[char_test],
	[ALL_TYPES].[bit],
	[ALL_TYPES].[binary],
	[ALL_TYPES].[bigint],
	[ALL_TYPES].[all_type_id],
	[ALL_TYPES].[created_by],
	[ALL_TYPES].[created_date],
	[ALL_TYPES].[modified_by],
	[ALL_TYPES].[modified_date],
	[ALL_TYPES].[time_stamp]

FROM 
[ALL_TYPES]
WHERE

	[ALL_TYPES].[all_type_id] IN (SELECT [all_type_id] 
											FROM OpenXML(@hDoc, '//ALL_TYPES', 2) 
											WITH ([all_type_id] char(36) 'all_type_id')) 


exec sp_xml_removeDocument @hDoc

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[gen_AllTypesSelectByAllTypesSinglePk]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [dbo].[gen_AllTypesSelectByAllTypesSinglePk]
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

CREATE PROCEDURE [dbo].[gen_AllTypesSelectByAllTypesSinglePk]
(
	@all_type_id UniqueIdentifier
)
AS

SELECT 
	[ALL_TYPES].[xml],
	[ALL_TYPES].[varcharmax],
	[ALL_TYPES].[varchar],
	[ALL_TYPES].[varbinarymax],
	[ALL_TYPES].[varbinary],
	[ALL_TYPES].[uniqueidentifier],
	[ALL_TYPES].[tinyint],
	[ALL_TYPES].[time],
	[ALL_TYPES].[text],
	[ALL_TYPES].[sql_variant],
	[ALL_TYPES].[smallmoney],
	[ALL_TYPES].[smallint],
	[ALL_TYPES].[smalldatetime],
	[ALL_TYPES].[real],
	[ALL_TYPES].[nvarcharmax],
	[ALL_TYPES].[nvarchar],
	[ALL_TYPES].[numeric],
	[ALL_TYPES].[ntext],
	[ALL_TYPES].[nchar],
	[ALL_TYPES].[money],
	[ALL_TYPES].[int_test],
	[ALL_TYPES].[image],
	[ALL_TYPES].[hierarchyid],
	[ALL_TYPES].[geometry],
	[ALL_TYPES].[geography],
	[ALL_TYPES].[float_test],
	[ALL_TYPES].[decimal_test],
	[ALL_TYPES].[datetimeoffset],
	[ALL_TYPES].[datetime2],
	[ALL_TYPES].[datetime],
	[ALL_TYPES].[date_test],
	[ALL_TYPES].[computedpersisted],
	[ALL_TYPES].[computednotpersisted],
	[ALL_TYPES].[char_test],
	[ALL_TYPES].[bit],
	[ALL_TYPES].[binary],
	[ALL_TYPES].[bigint],
	[ALL_TYPES].[all_type_id],
	[ALL_TYPES].[created_by],
	[ALL_TYPES].[created_date],
	[ALL_TYPES].[modified_by],
	[ALL_TYPES].[modified_date],
	[ALL_TYPES].[time_stamp]

FROM
[ALL_TYPES]
WHERE 
[ALL_TYPES].[all_type_id] = @all_type_id 
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[gen_AllTypesInsert]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [dbo].[gen_AllTypesInsert]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[gen_AllTypesInsert]
(
	@xml VarChar(max) = default,
	@varcharmax VarChar(max) = default,
	@varchar VarChar(50) = default,
	@varbinarymax VarBinary(max) = default,
	@varbinary VarBinary(50) = default,
	@uniqueidentifier UniqueIdentifier = default,
	@tinyint TinyInt = default,
	@time VarChar(5) = default,
	@text Text = default,
	@sql_variant VarChar(max) = default,
	@smallmoney SmallMoney = default,
	@smallint SmallInt = default,
	@smalldatetime SmallDateTime = default,
	@real Real = default,
	@nvarcharmax NVarChar(max) = default,
	@nvarchar NVarChar(50) = default,
	@numeric Decimal(18, 0) = default,
	@ntext NText = default,
	@nchar NChar(10) = default,
	@money Money = default,
	@int_test Int = default,
	@image Image = default,
	@hierarchyid VarChar(892) = default,
	@geometry VarChar(max) = default,
	@geography VarChar(max) = default,
	@float_test Float = default,
	@decimal_test Decimal(18, 0) = default,
	@datetimeoffset VarChar(10) = default,
	@datetime2 VarChar(8) = default,
	@datetime DateTime = default,
	@date_test VarChar(3) = default,
	@char_test Char(10) = default,
	@bit Bit = default,
	@binary Binary(50) = default,
	@BigInt BigInt = default,
	@all_type_id UniqueIdentifier = default,
	@created_date datetime,
	@created_by varchar (50),
	@modified_by varchar (50)

)
AS
SET NOCOUNT OFF;

if (@created_date IS NULL)
SET @created_date = GetDate()

INSERT INTO [ALL_TYPES]
(
[all_type_id],
[BigInt],
[binary],
[bit],
[char_test],
[date_test],
[datetime],
[datetime2],
[datetimeoffset],
[decimal_test],
[float_test],
[geography],
[geometry],
[hierarchyid],
[image],
[int_test],
[money],
[nchar],
[ntext],
[numeric],
[nvarchar],
[nvarcharmax],
[real],
[smalldatetime],
[smallint],
[smallmoney],
[sql_variant],
[text],
[time],
[tinyint],
[uniqueidentifier],
[varbinary],
[varbinarymax],
[varchar],
[varcharmax],
[xml],
[created_date],
[created_by],
[modified_date],
[modified_by]

)
VALUES
(
	@all_type_id,
	@BigInt,
	@binary,
	@bit,
	@char_test,
	@date_test,
	@datetime,
	@datetime2,
	@datetimeoffset,
	@decimal_test,
	@float_test,
	@geography,
	@geometry,
	@hierarchyid,
	@image,
	@int_test,
	@money,
	@nchar,
	@ntext,
	@numeric,
	@nvarchar,
	@nvarcharmax,
	@real,
	@smalldatetime,
	@smallint,
	@smallmoney,
	@sql_variant,
	@text,
	@time,
	@tinyint,
	@uniqueidentifier,
	@varbinary,
	@varbinarymax,
	@varchar,
	@varcharmax,
	@xml,
	@created_date,
	@created_by,
	@created_date,
	@modified_by

);


SELECT 
	[ALL_TYPES].[xml],
	[ALL_TYPES].[varcharmax],
	[ALL_TYPES].[varchar],
	[ALL_TYPES].[varbinarymax],
	[ALL_TYPES].[varbinary],
	[ALL_TYPES].[uniqueidentifier],
	[ALL_TYPES].[tinyint],
	[ALL_TYPES].[time],
	[ALL_TYPES].[text],
	[ALL_TYPES].[sql_variant],
	[ALL_TYPES].[smallmoney],
	[ALL_TYPES].[smallint],
	[ALL_TYPES].[smalldatetime],
	[ALL_TYPES].[real],
	[ALL_TYPES].[nvarcharmax],
	[ALL_TYPES].[nvarchar],
	[ALL_TYPES].[numeric],
	[ALL_TYPES].[ntext],
	[ALL_TYPES].[nchar],
	[ALL_TYPES].[money],
	[ALL_TYPES].[int_test],
	[ALL_TYPES].[image],
	[ALL_TYPES].[hierarchyid],
	[ALL_TYPES].[geometry],
	[ALL_TYPES].[geography],
	[ALL_TYPES].[float_test],
	[ALL_TYPES].[decimal_test],
	[ALL_TYPES].[datetimeoffset],
	[ALL_TYPES].[datetime2],
	[ALL_TYPES].[datetime],
	[ALL_TYPES].[date_test],
	[ALL_TYPES].[computedpersisted],
	[ALL_TYPES].[computednotpersisted],
	[ALL_TYPES].[char_test],
	[ALL_TYPES].[bit],
	[ALL_TYPES].[binary],
	[ALL_TYPES].[bigint],
	[ALL_TYPES].[all_type_id],
	[ALL_TYPES].[created_by],
	[ALL_TYPES].[created_date],
	[ALL_TYPES].[modified_by],
	[ALL_TYPES].[modified_date],
	[ALL_TYPES].[time_stamp]

FROM
[ALL_TYPES]
WHERE
	[ALL_TYPES].[all_type_id] = @all_type_id;
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[gen_AllTypesPagingSelect]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [dbo].[gen_AllTypesPagingSelect]
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

CREATE PROCEDURE [dbo].[gen_AllTypesPagingSelect]
(
	@page int, -- page number selected by the user
	@pageSize int, -- number of items on the page
	@orderByColumn varchar(100), -- name of column to order things by
	@ascending bit, -- order column ascending or descending
	@filter varchar(100) = null, -- filter statement passed in to determine like criteria on order by column
	@count int out -- number of items in the collection
)
AS

SET NOCOUNT ON;


CREATE TABLE #tmpTable
(
[all_type_id] UniqueIdentifier
)

DECLARE @total__ivqatedr int
DECLARE @orderByColumnIndex int
-- remove top x values from the temp table based upon the specific page requested
SET @total__ivqatedr = (@pageSize * @page)
IF (@total__ivqatedr <> 0)
BEGIN
	SET ROWCOUNT @total__ivqatedr
END
INSERT INTO #tmpTable
(
	[all_type_id]
)
SELECT
	[ALL_TYPES].[all_type_id]
FROM
[ALL_TYPES]
WHERE
	(@orderByColumn = 'xml' and (((@filter is null) or ([ALL_TYPES].[xml] is null)) or (@filter is not null and [ALL_TYPES].[xml] LIKE @filter)))
or
	(@orderByColumn = 'varcharmax' and (((@filter is null) or ([ALL_TYPES].[varcharmax] is null)) or (@filter is not null and [ALL_TYPES].[varcharmax] LIKE @filter)))
or
	(@orderByColumn = 'varchar' and (((@filter is null) or ([ALL_TYPES].[varchar] is null)) or (@filter is not null and [ALL_TYPES].[varchar] LIKE @filter)))
or
	(@orderByColumn = 'uniqueidentifier' and (((@filter is null) or ([ALL_TYPES].[uniqueidentifier] is null)) or (@filter is not null and [ALL_TYPES].[uniqueidentifier] = @filter)))
or
	(@orderByColumn = 'tinyint' and (((@filter is null) or ([ALL_TYPES].[tinyint] is null)) or (@filter is not null and [ALL_TYPES].[tinyint] = @filter)))
or
	(@orderByColumn = 'time' and (((@filter is null) or ([ALL_TYPES].[time] is null)) or (@filter is not null and [ALL_TYPES].[time] LIKE @filter)))
or
	(@orderByColumn = 'sql_variant' and (((@filter is null) or ([ALL_TYPES].[sql_variant] is null)) or (@filter is not null and [ALL_TYPES].[sql_variant] LIKE @filter)))
or
	(@orderByColumn = 'smallmoney' and (((@filter is null) or ([ALL_TYPES].[smallmoney] is null)) or (@filter is not null and [ALL_TYPES].[smallmoney] = @filter)))
or
	(@orderByColumn = 'smallint' and (((@filter is null) or ([ALL_TYPES].[smallint] is null)) or (@filter is not null and [ALL_TYPES].[smallint] = @filter)))
or
	(@orderByColumn = 'smalldatetime' and (((@filter is null) or ([ALL_TYPES].[smalldatetime] is null)) or (@filter is not null and [ALL_TYPES].[smalldatetime] = @filter)))
or
	(@orderByColumn = 'real' and (((@filter is null) or ([ALL_TYPES].[real] is null)) or (@filter is not null and [ALL_TYPES].[real] = @filter)))
or
	(@orderByColumn = 'nvarcharmax' and (((@filter is null) or ([ALL_TYPES].[nvarcharmax] is null)) or (@filter is not null and [ALL_TYPES].[nvarcharmax] LIKE @filter)))
or
	(@orderByColumn = 'nvarchar' and (((@filter is null) or ([ALL_TYPES].[nvarchar] is null)) or (@filter is not null and [ALL_TYPES].[nvarchar] LIKE @filter)))
or
	(@orderByColumn = 'numeric' and (((@filter is null) or ([ALL_TYPES].[numeric] is null)) or (@filter is not null and [ALL_TYPES].[numeric] = @filter)))
or
	(@orderByColumn = 'nchar' and (((@filter is null) or ([ALL_TYPES].[nchar] is null)) or (@filter is not null and [ALL_TYPES].[nchar] LIKE @filter)))
or
	(@orderByColumn = 'int_test' and (((@filter is null) or ([ALL_TYPES].[int_test] is null)) or (@filter is not null and [ALL_TYPES].[int_test] = @filter)))
or
	(@orderByColumn = 'hierarchyid' and (((@filter is null) or ([ALL_TYPES].[hierarchyid] is null)) or (@filter is not null and [ALL_TYPES].[hierarchyid] LIKE @filter)))
or
	(@orderByColumn = 'geometry' and (((@filter is null) or ([ALL_TYPES].[geometry] is null)) or (@filter is not null and [ALL_TYPES].[geometry] LIKE @filter)))
or
	(@orderByColumn = 'geography' and (((@filter is null) or ([ALL_TYPES].[geography] is null)) or (@filter is not null and [ALL_TYPES].[geography] LIKE @filter)))
or
	(@orderByColumn = 'float_test' and (((@filter is null) or ([ALL_TYPES].[float_test] is null)) or (@filter is not null and [ALL_TYPES].[float_test] = @filter)))
or
	(@orderByColumn = 'decimal_test' and (((@filter is null) or ([ALL_TYPES].[decimal_test] is null)) or (@filter is not null and [ALL_TYPES].[decimal_test] = @filter)))
or
	(@orderByColumn = 'datetimeoffset' and (((@filter is null) or ([ALL_TYPES].[datetimeoffset] is null)) or (@filter is not null and [ALL_TYPES].[datetimeoffset] LIKE @filter)))
or
	(@orderByColumn = 'datetime2' and (((@filter is null) or ([ALL_TYPES].[datetime2] is null)) or (@filter is not null and [ALL_TYPES].[datetime2] LIKE @filter)))
or
	(@orderByColumn = 'datetime' and (((@filter is null) or ([ALL_TYPES].[datetime] is null)) or (@filter is not null and [ALL_TYPES].[datetime] = @filter)))
or
	(@orderByColumn = 'date_test' and (((@filter is null) or ([ALL_TYPES].[date_test] is null)) or (@filter is not null and [ALL_TYPES].[date_test] LIKE @filter)))
or
	(@orderByColumn = 'computedPersisted' and (((@filter is null) or ([ALL_TYPES].[computedPersisted] is null)) or (@filter is not null and [ALL_TYPES].[computedPersisted] LIKE @filter)))
or
	(@orderByColumn = 'computedNotPersisted' and (((@filter is null) or ([ALL_TYPES].[computedNotPersisted] is null)) or (@filter is not null and [ALL_TYPES].[computedNotPersisted] LIKE @filter)))
or
	(@orderByColumn = 'char_test' and (((@filter is null) or ([ALL_TYPES].[char_test] is null)) or (@filter is not null and [ALL_TYPES].[char_test] LIKE @filter)))
or
	(@orderByColumn = 'bit' and (((@filter is null) or ([ALL_TYPES].[bit] is null)) or (@filter is not null and [ALL_TYPES].[bit] = @filter)))
or
	(@orderByColumn = 'BigInt' and (((@filter is null) or ([ALL_TYPES].[BigInt] is null)) or (@filter is not null and [ALL_TYPES].[BigInt] = @filter)))
or
	(@orderByColumn = 'all_type_id' and (((@filter is null) or ([ALL_TYPES].[all_type_id] is null)) or (@filter is not null and [ALL_TYPES].[all_type_id] = @filter)))
ORDER BY
	CASE @ascending WHEN 0 THEN CASE @orderByColumn WHEN 'xml' THEN [ALL_TYPES].[xml] END END DESC, 
	CASE @ascending WHEN 1 THEN CASE @orderByColumn WHEN 'xml' THEN [ALL_TYPES].[xml] END END, 
	CASE @ascending WHEN 0 THEN CASE @orderByColumn WHEN 'varcharmax' THEN [ALL_TYPES].[varcharmax] END END DESC, 
	CASE @ascending WHEN 1 THEN CASE @orderByColumn WHEN 'varcharmax' THEN [ALL_TYPES].[varcharmax] END END, 
	CASE @ascending WHEN 0 THEN CASE @orderByColumn WHEN 'varchar' THEN [ALL_TYPES].[varchar] END END DESC, 
	CASE @ascending WHEN 1 THEN CASE @orderByColumn WHEN 'varchar' THEN [ALL_TYPES].[varchar] END END, 
	CASE @ascending WHEN 0 THEN CASE @orderByColumn WHEN 'uniqueidentifier' THEN [ALL_TYPES].[uniqueidentifier] END END DESC, 
	CASE @ascending WHEN 1 THEN CASE @orderByColumn WHEN 'uniqueidentifier' THEN [ALL_TYPES].[uniqueidentifier] END END, 
	CASE @ascending WHEN 0 THEN CASE @orderByColumn WHEN 'tinyint' THEN [ALL_TYPES].[tinyint] END END DESC, 
	CASE @ascending WHEN 1 THEN CASE @orderByColumn WHEN 'tinyint' THEN [ALL_TYPES].[tinyint] END END, 
	CASE @ascending WHEN 0 THEN CASE @orderByColumn WHEN 'time' THEN [ALL_TYPES].[time] END END DESC, 
	CASE @ascending WHEN 1 THEN CASE @orderByColumn WHEN 'time' THEN [ALL_TYPES].[time] END END, 
	CASE @ascending WHEN 0 THEN CASE @orderByColumn WHEN 'sql_variant' THEN [ALL_TYPES].[sql_variant] END END DESC, 
	CASE @ascending WHEN 1 THEN CASE @orderByColumn WHEN 'sql_variant' THEN [ALL_TYPES].[sql_variant] END END, 
	CASE @ascending WHEN 0 THEN CASE @orderByColumn WHEN 'smallmoney' THEN [ALL_TYPES].[smallmoney] END END DESC, 
	CASE @ascending WHEN 1 THEN CASE @orderByColumn WHEN 'smallmoney' THEN [ALL_TYPES].[smallmoney] END END, 
	CASE @ascending WHEN 0 THEN CASE @orderByColumn WHEN 'smallint' THEN [ALL_TYPES].[smallint] END END DESC, 
	CASE @ascending WHEN 1 THEN CASE @orderByColumn WHEN 'smallint' THEN [ALL_TYPES].[smallint] END END, 
	CASE @ascending WHEN 0 THEN CASE @orderByColumn WHEN 'smalldatetime' THEN [ALL_TYPES].[smalldatetime] END END DESC, 
	CASE @ascending WHEN 1 THEN CASE @orderByColumn WHEN 'smalldatetime' THEN [ALL_TYPES].[smalldatetime] END END, 
	CASE @ascending WHEN 0 THEN CASE @orderByColumn WHEN 'real' THEN [ALL_TYPES].[real] END END DESC, 
	CASE @ascending WHEN 1 THEN CASE @orderByColumn WHEN 'real' THEN [ALL_TYPES].[real] END END, 
	CASE @ascending WHEN 0 THEN CASE @orderByColumn WHEN 'nvarcharmax' THEN [ALL_TYPES].[nvarcharmax] END END DESC, 
	CASE @ascending WHEN 1 THEN CASE @orderByColumn WHEN 'nvarcharmax' THEN [ALL_TYPES].[nvarcharmax] END END, 
	CASE @ascending WHEN 0 THEN CASE @orderByColumn WHEN 'nvarchar' THEN [ALL_TYPES].[nvarchar] END END DESC, 
	CASE @ascending WHEN 1 THEN CASE @orderByColumn WHEN 'nvarchar' THEN [ALL_TYPES].[nvarchar] END END, 
	CASE @ascending WHEN 0 THEN CASE @orderByColumn WHEN 'numeric' THEN [ALL_TYPES].[numeric] END END DESC, 
	CASE @ascending WHEN 1 THEN CASE @orderByColumn WHEN 'numeric' THEN [ALL_TYPES].[numeric] END END, 
	CASE @ascending WHEN 0 THEN CASE @orderByColumn WHEN 'nchar' THEN [ALL_TYPES].[nchar] END END DESC, 
	CASE @ascending WHEN 1 THEN CASE @orderByColumn WHEN 'nchar' THEN [ALL_TYPES].[nchar] END END, 
	CASE @ascending WHEN 0 THEN CASE @orderByColumn WHEN 'int_test' THEN [ALL_TYPES].[int_test] END END DESC, 
	CASE @ascending WHEN 1 THEN CASE @orderByColumn WHEN 'int_test' THEN [ALL_TYPES].[int_test] END END, 
	CASE @ascending WHEN 0 THEN CASE @orderByColumn WHEN 'hierarchyid' THEN [ALL_TYPES].[hierarchyid] END END DESC, 
	CASE @ascending WHEN 1 THEN CASE @orderByColumn WHEN 'hierarchyid' THEN [ALL_TYPES].[hierarchyid] END END, 
	CASE @ascending WHEN 0 THEN CASE @orderByColumn WHEN 'geometry' THEN [ALL_TYPES].[geometry] END END DESC, 
	CASE @ascending WHEN 1 THEN CASE @orderByColumn WHEN 'geometry' THEN [ALL_TYPES].[geometry] END END, 
	CASE @ascending WHEN 0 THEN CASE @orderByColumn WHEN 'geography' THEN [ALL_TYPES].[geography] END END DESC, 
	CASE @ascending WHEN 1 THEN CASE @orderByColumn WHEN 'geography' THEN [ALL_TYPES].[geography] END END, 
	CASE @ascending WHEN 0 THEN CASE @orderByColumn WHEN 'float_test' THEN [ALL_TYPES].[float_test] END END DESC, 
	CASE @ascending WHEN 1 THEN CASE @orderByColumn WHEN 'float_test' THEN [ALL_TYPES].[float_test] END END, 
	CASE @ascending WHEN 0 THEN CASE @orderByColumn WHEN 'decimal_test' THEN [ALL_TYPES].[decimal_test] END END DESC, 
	CASE @ascending WHEN 1 THEN CASE @orderByColumn WHEN 'decimal_test' THEN [ALL_TYPES].[decimal_test] END END, 
	CASE @ascending WHEN 0 THEN CASE @orderByColumn WHEN 'datetimeoffset' THEN [ALL_TYPES].[datetimeoffset] END END DESC, 
	CASE @ascending WHEN 1 THEN CASE @orderByColumn WHEN 'datetimeoffset' THEN [ALL_TYPES].[datetimeoffset] END END, 
	CASE @ascending WHEN 0 THEN CASE @orderByColumn WHEN 'datetime2' THEN [ALL_TYPES].[datetime2] END END DESC, 
	CASE @ascending WHEN 1 THEN CASE @orderByColumn WHEN 'datetime2' THEN [ALL_TYPES].[datetime2] END END, 
	CASE @ascending WHEN 0 THEN CASE @orderByColumn WHEN 'datetime' THEN [ALL_TYPES].[datetime] END END DESC, 
	CASE @ascending WHEN 1 THEN CASE @orderByColumn WHEN 'datetime' THEN [ALL_TYPES].[datetime] END END, 
	CASE @ascending WHEN 0 THEN CASE @orderByColumn WHEN 'date_test' THEN [ALL_TYPES].[date_test] END END DESC, 
	CASE @ascending WHEN 1 THEN CASE @orderByColumn WHEN 'date_test' THEN [ALL_TYPES].[date_test] END END, 
	CASE @ascending WHEN 0 THEN CASE @orderByColumn WHEN 'computedPersisted' THEN [ALL_TYPES].[computedPersisted] END END DESC, 
	CASE @ascending WHEN 1 THEN CASE @orderByColumn WHEN 'computedPersisted' THEN [ALL_TYPES].[computedPersisted] END END, 
	CASE @ascending WHEN 0 THEN CASE @orderByColumn WHEN 'computedNotPersisted' THEN [ALL_TYPES].[computedNotPersisted] END END DESC, 
	CASE @ascending WHEN 1 THEN CASE @orderByColumn WHEN 'computedNotPersisted' THEN [ALL_TYPES].[computedNotPersisted] END END, 
	CASE @ascending WHEN 0 THEN CASE @orderByColumn WHEN 'char_test' THEN [ALL_TYPES].[char_test] END END DESC, 
	CASE @ascending WHEN 1 THEN CASE @orderByColumn WHEN 'char_test' THEN [ALL_TYPES].[char_test] END END, 
	CASE @ascending WHEN 0 THEN CASE @orderByColumn WHEN 'bit' THEN [ALL_TYPES].[bit] END END DESC, 
	CASE @ascending WHEN 1 THEN CASE @orderByColumn WHEN 'bit' THEN [ALL_TYPES].[bit] END END, 
	CASE @ascending WHEN 0 THEN CASE @orderByColumn WHEN 'BigInt' THEN [ALL_TYPES].[BigInt] END END DESC, 
	CASE @ascending WHEN 1 THEN CASE @orderByColumn WHEN 'BigInt' THEN [ALL_TYPES].[BigInt] END END, 
	CASE @ascending WHEN 0 THEN CASE @orderByColumn WHEN 'all_type_id' THEN [ALL_TYPES].[all_type_id] END END DESC, 
	CASE @ascending WHEN 1 THEN CASE @orderByColumn WHEN 'all_type_id' THEN [ALL_TYPES].[all_type_id] END END

-- set @count based on the rows moved in the previous statement
SET ROWCOUNT 0
SET @count = (
SELECT count(*)
FROM
[ALL_TYPES]
WHERE
	(@orderByColumn = 'xml' and (((@filter is null) or ([ALL_TYPES].[xml] is null)) or (@filter is not null and [ALL_TYPES].[xml] LIKE @filter)))
or
	(@orderByColumn = 'varcharmax' and (((@filter is null) or ([ALL_TYPES].[varcharmax] is null)) or (@filter is not null and [ALL_TYPES].[varcharmax] LIKE @filter)))
or
	(@orderByColumn = 'varchar' and (((@filter is null) or ([ALL_TYPES].[varchar] is null)) or (@filter is not null and [ALL_TYPES].[varchar] LIKE @filter)))
or
	(@orderByColumn = 'uniqueidentifier' and (((@filter is null) or ([ALL_TYPES].[uniqueidentifier] is null)) or (@filter is not null and [ALL_TYPES].[uniqueidentifier] = @filter)))
or
	(@orderByColumn = 'tinyint' and (((@filter is null) or ([ALL_TYPES].[tinyint] is null)) or (@filter is not null and [ALL_TYPES].[tinyint] = @filter)))
or
	(@orderByColumn = 'time' and (((@filter is null) or ([ALL_TYPES].[time] is null)) or (@filter is not null and [ALL_TYPES].[time] LIKE @filter)))
or
	(@orderByColumn = 'sql_variant' and (((@filter is null) or ([ALL_TYPES].[sql_variant] is null)) or (@filter is not null and [ALL_TYPES].[sql_variant] LIKE @filter)))
or
	(@orderByColumn = 'smallmoney' and (((@filter is null) or ([ALL_TYPES].[smallmoney] is null)) or (@filter is not null and [ALL_TYPES].[smallmoney] = @filter)))
or
	(@orderByColumn = 'smallint' and (((@filter is null) or ([ALL_TYPES].[smallint] is null)) or (@filter is not null and [ALL_TYPES].[smallint] = @filter)))
or
	(@orderByColumn = 'smalldatetime' and (((@filter is null) or ([ALL_TYPES].[smalldatetime] is null)) or (@filter is not null and [ALL_TYPES].[smalldatetime] = @filter)))
or
	(@orderByColumn = 'real' and (((@filter is null) or ([ALL_TYPES].[real] is null)) or (@filter is not null and [ALL_TYPES].[real] = @filter)))
or
	(@orderByColumn = 'nvarcharmax' and (((@filter is null) or ([ALL_TYPES].[nvarcharmax] is null)) or (@filter is not null and [ALL_TYPES].[nvarcharmax] LIKE @filter)))
or
	(@orderByColumn = 'nvarchar' and (((@filter is null) or ([ALL_TYPES].[nvarchar] is null)) or (@filter is not null and [ALL_TYPES].[nvarchar] LIKE @filter)))
or
	(@orderByColumn = 'numeric' and (((@filter is null) or ([ALL_TYPES].[numeric] is null)) or (@filter is not null and [ALL_TYPES].[numeric] = @filter)))
or
	(@orderByColumn = 'nchar' and (((@filter is null) or ([ALL_TYPES].[nchar] is null)) or (@filter is not null and [ALL_TYPES].[nchar] LIKE @filter)))
or
	(@orderByColumn = 'int_test' and (((@filter is null) or ([ALL_TYPES].[int_test] is null)) or (@filter is not null and [ALL_TYPES].[int_test] = @filter)))
or
	(@orderByColumn = 'hierarchyid' and (((@filter is null) or ([ALL_TYPES].[hierarchyid] is null)) or (@filter is not null and [ALL_TYPES].[hierarchyid] LIKE @filter)))
or
	(@orderByColumn = 'geometry' and (((@filter is null) or ([ALL_TYPES].[geometry] is null)) or (@filter is not null and [ALL_TYPES].[geometry] LIKE @filter)))
or
	(@orderByColumn = 'geography' and (((@filter is null) or ([ALL_TYPES].[geography] is null)) or (@filter is not null and [ALL_TYPES].[geography] LIKE @filter)))
or
	(@orderByColumn = 'float_test' and (((@filter is null) or ([ALL_TYPES].[float_test] is null)) or (@filter is not null and [ALL_TYPES].[float_test] = @filter)))
or
	(@orderByColumn = 'decimal_test' and (((@filter is null) or ([ALL_TYPES].[decimal_test] is null)) or (@filter is not null and [ALL_TYPES].[decimal_test] = @filter)))
or
	(@orderByColumn = 'datetimeoffset' and (((@filter is null) or ([ALL_TYPES].[datetimeoffset] is null)) or (@filter is not null and [ALL_TYPES].[datetimeoffset] LIKE @filter)))
or
	(@orderByColumn = 'datetime2' and (((@filter is null) or ([ALL_TYPES].[datetime2] is null)) or (@filter is not null and [ALL_TYPES].[datetime2] LIKE @filter)))
or
	(@orderByColumn = 'datetime' and (((@filter is null) or ([ALL_TYPES].[datetime] is null)) or (@filter is not null and [ALL_TYPES].[datetime] = @filter)))
or
	(@orderByColumn = 'date_test' and (((@filter is null) or ([ALL_TYPES].[date_test] is null)) or (@filter is not null and [ALL_TYPES].[date_test] LIKE @filter)))
or
	(@orderByColumn = 'computedPersisted' and (((@filter is null) or ([ALL_TYPES].[computedPersisted] is null)) or (@filter is not null and [ALL_TYPES].[computedPersisted] LIKE @filter)))
or
	(@orderByColumn = 'computedNotPersisted' and (((@filter is null) or ([ALL_TYPES].[computedNotPersisted] is null)) or (@filter is not null and [ALL_TYPES].[computedNotPersisted] LIKE @filter)))
or
	(@orderByColumn = 'char_test' and (((@filter is null) or ([ALL_TYPES].[char_test] is null)) or (@filter is not null and [ALL_TYPES].[char_test] LIKE @filter)))
or
	(@orderByColumn = 'bit' and (((@filter is null) or ([ALL_TYPES].[bit] is null)) or (@filter is not null and [ALL_TYPES].[bit] = @filter)))
or
	(@orderByColumn = 'BigInt' and (((@filter is null) or ([ALL_TYPES].[BigInt] is null)) or (@filter is not null and [ALL_TYPES].[BigInt] = @filter)))
or
	(@orderByColumn = 'all_type_id' and (((@filter is null) or ([ALL_TYPES].[all_type_id] is null)) or (@filter is not null and [ALL_TYPES].[all_type_id] = @filter)))
)

-- remove top x values from the temp table based upon the specific page requested
SET @total__ivqatedr = (@pageSize * @page) - @pageSize
IF (@total__ivqatedr <> 0)
BEGIN
	SET ROWCOUNT @total__ivqatedr
	DELETE FROM #tmpTable
END

-- return the number of rows requested as the page size
SET ROWCOUNT @pageSize
SELECT
	[ALL_TYPES].[xml],
	[ALL_TYPES].[varcharmax],
	[ALL_TYPES].[varchar],
	[ALL_TYPES].[varbinarymax],
	[ALL_TYPES].[varbinary],
	[ALL_TYPES].[uniqueidentifier],
	[ALL_TYPES].[tinyint],
	[ALL_TYPES].[time],
	[ALL_TYPES].[text],
	[ALL_TYPES].[sql_variant],
	[ALL_TYPES].[smallmoney],
	[ALL_TYPES].[smallint],
	[ALL_TYPES].[smalldatetime],
	[ALL_TYPES].[real],
	[ALL_TYPES].[nvarcharmax],
	[ALL_TYPES].[nvarchar],
	[ALL_TYPES].[numeric],
	[ALL_TYPES].[ntext],
	[ALL_TYPES].[nchar],
	[ALL_TYPES].[money],
	[ALL_TYPES].[int_test],
	[ALL_TYPES].[image],
	[ALL_TYPES].[hierarchyid],
	[ALL_TYPES].[geometry],
	[ALL_TYPES].[geography],
	[ALL_TYPES].[float_test],
	[ALL_TYPES].[decimal_test],
	[ALL_TYPES].[datetimeoffset],
	[ALL_TYPES].[datetime2],
	[ALL_TYPES].[datetime],
	[ALL_TYPES].[date_test],
	[ALL_TYPES].[computedpersisted],
	[ALL_TYPES].[computednotpersisted],
	[ALL_TYPES].[char_test],
	[ALL_TYPES].[bit],
	[ALL_TYPES].[binary],
	[ALL_TYPES].[bigint],
	[ALL_TYPES].[all_type_id],
	[ALL_TYPES].[created_by],
	[ALL_TYPES].[created_date],
	[ALL_TYPES].[modified_by],
	[ALL_TYPES].[modified_date],
	[ALL_TYPES].[time_stamp]
FROM
	[#tmpTable]
	INNER JOIN [ALL_TYPES] ON #tmpTable.[all_type_id] = [ALL_TYPES].[all_type_id]
ORDER BY
	CASE @ascending WHEN 0 THEN CASE @orderByColumn WHEN 'xml' THEN [ALL_TYPES].[xml] END END DESC, 
	CASE @ascending WHEN 1 THEN CASE @orderByColumn WHEN 'xml' THEN [ALL_TYPES].[xml] END END, 
	CASE @ascending WHEN 0 THEN CASE @orderByColumn WHEN 'varcharmax' THEN [ALL_TYPES].[varcharmax] END END DESC, 
	CASE @ascending WHEN 1 THEN CASE @orderByColumn WHEN 'varcharmax' THEN [ALL_TYPES].[varcharmax] END END, 
	CASE @ascending WHEN 0 THEN CASE @orderByColumn WHEN 'varchar' THEN [ALL_TYPES].[varchar] END END DESC, 
	CASE @ascending WHEN 1 THEN CASE @orderByColumn WHEN 'varchar' THEN [ALL_TYPES].[varchar] END END, 
	CASE @ascending WHEN 0 THEN CASE @orderByColumn WHEN 'uniqueidentifier' THEN [ALL_TYPES].[uniqueidentifier] END END DESC, 
	CASE @ascending WHEN 1 THEN CASE @orderByColumn WHEN 'uniqueidentifier' THEN [ALL_TYPES].[uniqueidentifier] END END, 
	CASE @ascending WHEN 0 THEN CASE @orderByColumn WHEN 'tinyint' THEN [ALL_TYPES].[tinyint] END END DESC, 
	CASE @ascending WHEN 1 THEN CASE @orderByColumn WHEN 'tinyint' THEN [ALL_TYPES].[tinyint] END END, 
	CASE @ascending WHEN 0 THEN CASE @orderByColumn WHEN 'time' THEN [ALL_TYPES].[time] END END DESC, 
	CASE @ascending WHEN 1 THEN CASE @orderByColumn WHEN 'time' THEN [ALL_TYPES].[time] END END, 
	CASE @ascending WHEN 0 THEN CASE @orderByColumn WHEN 'sql_variant' THEN [ALL_TYPES].[sql_variant] END END DESC, 
	CASE @ascending WHEN 1 THEN CASE @orderByColumn WHEN 'sql_variant' THEN [ALL_TYPES].[sql_variant] END END, 
	CASE @ascending WHEN 0 THEN CASE @orderByColumn WHEN 'smallmoney' THEN [ALL_TYPES].[smallmoney] END END DESC, 
	CASE @ascending WHEN 1 THEN CASE @orderByColumn WHEN 'smallmoney' THEN [ALL_TYPES].[smallmoney] END END, 
	CASE @ascending WHEN 0 THEN CASE @orderByColumn WHEN 'smallint' THEN [ALL_TYPES].[smallint] END END DESC, 
	CASE @ascending WHEN 1 THEN CASE @orderByColumn WHEN 'smallint' THEN [ALL_TYPES].[smallint] END END, 
	CASE @ascending WHEN 0 THEN CASE @orderByColumn WHEN 'smalldatetime' THEN [ALL_TYPES].[smalldatetime] END END DESC, 
	CASE @ascending WHEN 1 THEN CASE @orderByColumn WHEN 'smalldatetime' THEN [ALL_TYPES].[smalldatetime] END END, 
	CASE @ascending WHEN 0 THEN CASE @orderByColumn WHEN 'real' THEN [ALL_TYPES].[real] END END DESC, 
	CASE @ascending WHEN 1 THEN CASE @orderByColumn WHEN 'real' THEN [ALL_TYPES].[real] END END, 
	CASE @ascending WHEN 0 THEN CASE @orderByColumn WHEN 'nvarcharmax' THEN [ALL_TYPES].[nvarcharmax] END END DESC, 
	CASE @ascending WHEN 1 THEN CASE @orderByColumn WHEN 'nvarcharmax' THEN [ALL_TYPES].[nvarcharmax] END END, 
	CASE @ascending WHEN 0 THEN CASE @orderByColumn WHEN 'nvarchar' THEN [ALL_TYPES].[nvarchar] END END DESC, 
	CASE @ascending WHEN 1 THEN CASE @orderByColumn WHEN 'nvarchar' THEN [ALL_TYPES].[nvarchar] END END, 
	CASE @ascending WHEN 0 THEN CASE @orderByColumn WHEN 'numeric' THEN [ALL_TYPES].[numeric] END END DESC, 
	CASE @ascending WHEN 1 THEN CASE @orderByColumn WHEN 'numeric' THEN [ALL_TYPES].[numeric] END END, 
	CASE @ascending WHEN 0 THEN CASE @orderByColumn WHEN 'nchar' THEN [ALL_TYPES].[nchar] END END DESC, 
	CASE @ascending WHEN 1 THEN CASE @orderByColumn WHEN 'nchar' THEN [ALL_TYPES].[nchar] END END, 
	CASE @ascending WHEN 0 THEN CASE @orderByColumn WHEN 'int_test' THEN [ALL_TYPES].[int_test] END END DESC, 
	CASE @ascending WHEN 1 THEN CASE @orderByColumn WHEN 'int_test' THEN [ALL_TYPES].[int_test] END END, 
	CASE @ascending WHEN 0 THEN CASE @orderByColumn WHEN 'hierarchyid' THEN [ALL_TYPES].[hierarchyid] END END DESC, 
	CASE @ascending WHEN 1 THEN CASE @orderByColumn WHEN 'hierarchyid' THEN [ALL_TYPES].[hierarchyid] END END, 
	CASE @ascending WHEN 0 THEN CASE @orderByColumn WHEN 'geometry' THEN [ALL_TYPES].[geometry] END END DESC, 
	CASE @ascending WHEN 1 THEN CASE @orderByColumn WHEN 'geometry' THEN [ALL_TYPES].[geometry] END END, 
	CASE @ascending WHEN 0 THEN CASE @orderByColumn WHEN 'geography' THEN [ALL_TYPES].[geography] END END DESC, 
	CASE @ascending WHEN 1 THEN CASE @orderByColumn WHEN 'geography' THEN [ALL_TYPES].[geography] END END, 
	CASE @ascending WHEN 0 THEN CASE @orderByColumn WHEN 'float_test' THEN [ALL_TYPES].[float_test] END END DESC, 
	CASE @ascending WHEN 1 THEN CASE @orderByColumn WHEN 'float_test' THEN [ALL_TYPES].[float_test] END END, 
	CASE @ascending WHEN 0 THEN CASE @orderByColumn WHEN 'decimal_test' THEN [ALL_TYPES].[decimal_test] END END DESC, 
	CASE @ascending WHEN 1 THEN CASE @orderByColumn WHEN 'decimal_test' THEN [ALL_TYPES].[decimal_test] END END, 
	CASE @ascending WHEN 0 THEN CASE @orderByColumn WHEN 'datetimeoffset' THEN [ALL_TYPES].[datetimeoffset] END END DESC, 
	CASE @ascending WHEN 1 THEN CASE @orderByColumn WHEN 'datetimeoffset' THEN [ALL_TYPES].[datetimeoffset] END END, 
	CASE @ascending WHEN 0 THEN CASE @orderByColumn WHEN 'datetime2' THEN [ALL_TYPES].[datetime2] END END DESC, 
	CASE @ascending WHEN 1 THEN CASE @orderByColumn WHEN 'datetime2' THEN [ALL_TYPES].[datetime2] END END, 
	CASE @ascending WHEN 0 THEN CASE @orderByColumn WHEN 'datetime' THEN [ALL_TYPES].[datetime] END END DESC, 
	CASE @ascending WHEN 1 THEN CASE @orderByColumn WHEN 'datetime' THEN [ALL_TYPES].[datetime] END END, 
	CASE @ascending WHEN 0 THEN CASE @orderByColumn WHEN 'date_test' THEN [ALL_TYPES].[date_test] END END DESC, 
	CASE @ascending WHEN 1 THEN CASE @orderByColumn WHEN 'date_test' THEN [ALL_TYPES].[date_test] END END, 
	CASE @ascending WHEN 0 THEN CASE @orderByColumn WHEN 'computedPersisted' THEN [ALL_TYPES].[computedPersisted] END END DESC, 
	CASE @ascending WHEN 1 THEN CASE @orderByColumn WHEN 'computedPersisted' THEN [ALL_TYPES].[computedPersisted] END END, 
	CASE @ascending WHEN 0 THEN CASE @orderByColumn WHEN 'computedNotPersisted' THEN [ALL_TYPES].[computedNotPersisted] END END DESC, 
	CASE @ascending WHEN 1 THEN CASE @orderByColumn WHEN 'computedNotPersisted' THEN [ALL_TYPES].[computedNotPersisted] END END, 
	CASE @ascending WHEN 0 THEN CASE @orderByColumn WHEN 'char_test' THEN [ALL_TYPES].[char_test] END END DESC, 
	CASE @ascending WHEN 1 THEN CASE @orderByColumn WHEN 'char_test' THEN [ALL_TYPES].[char_test] END END, 
	CASE @ascending WHEN 0 THEN CASE @orderByColumn WHEN 'bit' THEN [ALL_TYPES].[bit] END END DESC, 
	CASE @ascending WHEN 1 THEN CASE @orderByColumn WHEN 'bit' THEN [ALL_TYPES].[bit] END END, 
	CASE @ascending WHEN 0 THEN CASE @orderByColumn WHEN 'BigInt' THEN [ALL_TYPES].[BigInt] END END DESC, 
	CASE @ascending WHEN 1 THEN CASE @orderByColumn WHEN 'BigInt' THEN [ALL_TYPES].[BigInt] END END, 
	CASE @ascending WHEN 0 THEN CASE @orderByColumn WHEN 'all_type_id' THEN [ALL_TYPES].[all_type_id] END END DESC, 
	CASE @ascending WHEN 1 THEN CASE @orderByColumn WHEN 'all_type_id' THEN [ALL_TYPES].[all_type_id] END END

DROP TABLE #tmpTable

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[gen_AllTypesSelectBySearchAnd]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [dbo].[gen_AllTypesSelectBySearchAnd]
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

CREATE PROCEDURE [dbo].[gen_AllTypesSelectBySearchAnd]
(
	@xml VarChar(max) = null, 
	@varcharmax VarChar(max) = null, 
	@varchar VarChar(50) = null, 
	@uniqueidentifier UniqueIdentifier = null, 
	@tinyint TinyInt = null, 
	@time VarChar(5) = null, 
	@sql_variant VarChar(max) = null, 
	@smallmoney SmallMoney = null, 
	@smallint SmallInt = null, 
	@smalldatetime SmallDateTime = null, 
	@real Real = null, 
	@nvarcharmax NVarChar(max) = null, 
	@nvarchar NVarChar(50) = null, 
	@numeric Decimal = null, 
	@nchar NChar(10) = null, 
	@int_test Int = null, 
	@hierarchyid VarChar(892) = null, 
	@geometry VarChar(max) = null, 
	@geography VarChar(max) = null, 
	@float_test Float = null, 
	@decimal_test Decimal = null, 
	@datetimeoffset VarChar(10) = null, 
	@datetime2 VarChar(8) = null, 
	@datetime DateTime = null, 
	@date_test VarChar(3) = null, 
	@computedPersisted VarChar(1) = null, 
	@computedNotPersisted VarChar(1) = null, 
	@char_test Char(10) = null, 
	@bit Bit = null, 
	@BigInt BigInt = null, 
	@all_type_id UniqueIdentifier = null, 
	@paging_PageIndex int = -1, -- page number selected by the user
	@paging_RecordsperPage int = -1, -- number of items on the page
	@paging_OrderByColumn varchar(100) = '', -- name of column to order things by
	@paging_Ascending bit = 1, -- order column ascending or descending
	@paging_Count int out -- number of items in the collection
)
AS

CREATE TABLE #tmpTable 
(
	[all_type_id] UniqueIdentifier
)

DECLARE @total__ivqatedr int
DECLARE @orderByColumnIndex int
-- remove top x values from the temp table based upon the specific page requested
SET @total__ivqatedr = (@paging_RecordsperPage * @paging_PageIndex)
IF (@total__ivqatedr <> 0) AND (@paging_PageIndex <> -1)
BEGIN
	SET ROWCOUNT @total__ivqatedr
END
INSERT INTO #tmpTable
(
	[all_type_id]
)
SELECT
	[ALL_TYPES].[all_type_id]
FROM
[ALL_TYPES]
WHERE
((@xml is null) OR ([ALL_TYPES].[xml] LIKE @xml)) AND
((@varcharmax is null) OR ([ALL_TYPES].[varcharmax] LIKE @varcharmax)) AND
((@varchar is null) OR ([ALL_TYPES].[varchar] LIKE @varchar)) AND
((@uniqueidentifier is null) OR ([ALL_TYPES].[uniqueidentifier] = @uniqueidentifier)) AND
((@tinyint is null) OR ([ALL_TYPES].[tinyint] = @tinyint)) AND
((@time is null) OR ([ALL_TYPES].[time] LIKE @time)) AND
((@sql_variant is null) OR ([ALL_TYPES].[sql_variant] LIKE @sql_variant)) AND
((@smallmoney is null) OR ([ALL_TYPES].[smallmoney] = @smallmoney)) AND
((@smallint is null) OR ([ALL_TYPES].[smallint] = @smallint)) AND
((@smalldatetime is null) OR ([ALL_TYPES].[smalldatetime] = @smalldatetime)) AND
((@real is null) OR ([ALL_TYPES].[real] = @real)) AND
((@nvarcharmax is null) OR ([ALL_TYPES].[nvarcharmax] LIKE @nvarcharmax)) AND
((@nvarchar is null) OR ([ALL_TYPES].[nvarchar] LIKE @nvarchar)) AND
((@numeric is null) OR ([ALL_TYPES].[numeric] = @numeric)) AND
((@nchar is null) OR ([ALL_TYPES].[nchar] LIKE @nchar)) AND
((@int_test is null) OR ([ALL_TYPES].[int_test] = @int_test)) AND
((@hierarchyid is null) OR ([ALL_TYPES].[hierarchyid] LIKE @hierarchyid)) AND
((@geometry is null) OR ([ALL_TYPES].[geometry] LIKE @geometry)) AND
((@geography is null) OR ([ALL_TYPES].[geography] LIKE @geography)) AND
((@float_test is null) OR ([ALL_TYPES].[float_test] = @float_test)) AND
((@decimal_test is null) OR ([ALL_TYPES].[decimal_test] = @decimal_test)) AND
((@datetimeoffset is null) OR ([ALL_TYPES].[datetimeoffset] LIKE @datetimeoffset)) AND
((@datetime2 is null) OR ([ALL_TYPES].[datetime2] LIKE @datetime2)) AND
((@datetime is null) OR ([ALL_TYPES].[datetime] = @datetime)) AND
((@date_test is null) OR ([ALL_TYPES].[date_test] LIKE @date_test)) AND
((@computedPersisted is null) OR ([ALL_TYPES].[computedPersisted] LIKE @computedPersisted)) AND
((@computedNotPersisted is null) OR ([ALL_TYPES].[computedNotPersisted] LIKE @computedNotPersisted)) AND
((@char_test is null) OR ([ALL_TYPES].[char_test] LIKE @char_test)) AND
((@bit is null) OR ([ALL_TYPES].[bit] = @bit)) AND
((@BigInt is null) OR ([ALL_TYPES].[BigInt] = @BigInt)) AND
((@all_type_id is null) OR ([ALL_TYPES].[all_type_id] = @all_type_id))
ORDER BY
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'xml' THEN [ALL_TYPES].[xml] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'xml' THEN [ALL_TYPES].[xml] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'varcharmax' THEN [ALL_TYPES].[varcharmax] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'varcharmax' THEN [ALL_TYPES].[varcharmax] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'varchar' THEN [ALL_TYPES].[varchar] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'varchar' THEN [ALL_TYPES].[varchar] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'uniqueidentifier' THEN [ALL_TYPES].[uniqueidentifier] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'uniqueidentifier' THEN [ALL_TYPES].[uniqueidentifier] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'tinyint' THEN [ALL_TYPES].[tinyint] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'tinyint' THEN [ALL_TYPES].[tinyint] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'time' THEN [ALL_TYPES].[time] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'time' THEN [ALL_TYPES].[time] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'sql_variant' THEN [ALL_TYPES].[sql_variant] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'sql_variant' THEN [ALL_TYPES].[sql_variant] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'smallmoney' THEN [ALL_TYPES].[smallmoney] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'smallmoney' THEN [ALL_TYPES].[smallmoney] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'smallint' THEN [ALL_TYPES].[smallint] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'smallint' THEN [ALL_TYPES].[smallint] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'smalldatetime' THEN [ALL_TYPES].[smalldatetime] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'smalldatetime' THEN [ALL_TYPES].[smalldatetime] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'real' THEN [ALL_TYPES].[real] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'real' THEN [ALL_TYPES].[real] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'nvarcharmax' THEN [ALL_TYPES].[nvarcharmax] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'nvarcharmax' THEN [ALL_TYPES].[nvarcharmax] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'nvarchar' THEN [ALL_TYPES].[nvarchar] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'nvarchar' THEN [ALL_TYPES].[nvarchar] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'numeric' THEN [ALL_TYPES].[numeric] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'numeric' THEN [ALL_TYPES].[numeric] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'nchar' THEN [ALL_TYPES].[nchar] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'nchar' THEN [ALL_TYPES].[nchar] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'int_test' THEN [ALL_TYPES].[int_test] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'int_test' THEN [ALL_TYPES].[int_test] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'hierarchyid' THEN [ALL_TYPES].[hierarchyid] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'hierarchyid' THEN [ALL_TYPES].[hierarchyid] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'geometry' THEN [ALL_TYPES].[geometry] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'geometry' THEN [ALL_TYPES].[geometry] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'geography' THEN [ALL_TYPES].[geography] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'geography' THEN [ALL_TYPES].[geography] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'float_test' THEN [ALL_TYPES].[float_test] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'float_test' THEN [ALL_TYPES].[float_test] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'decimal_test' THEN [ALL_TYPES].[decimal_test] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'decimal_test' THEN [ALL_TYPES].[decimal_test] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'datetimeoffset' THEN [ALL_TYPES].[datetimeoffset] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'datetimeoffset' THEN [ALL_TYPES].[datetimeoffset] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'datetime2' THEN [ALL_TYPES].[datetime2] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'datetime2' THEN [ALL_TYPES].[datetime2] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'datetime' THEN [ALL_TYPES].[datetime] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'datetime' THEN [ALL_TYPES].[datetime] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'date_test' THEN [ALL_TYPES].[date_test] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'date_test' THEN [ALL_TYPES].[date_test] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'computedPersisted' THEN [ALL_TYPES].[computedPersisted] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'computedPersisted' THEN [ALL_TYPES].[computedPersisted] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'computedNotPersisted' THEN [ALL_TYPES].[computedNotPersisted] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'computedNotPersisted' THEN [ALL_TYPES].[computedNotPersisted] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'char_test' THEN [ALL_TYPES].[char_test] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'char_test' THEN [ALL_TYPES].[char_test] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'bit' THEN [ALL_TYPES].[bit] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'bit' THEN [ALL_TYPES].[bit] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'BigInt' THEN [ALL_TYPES].[BigInt] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'BigInt' THEN [ALL_TYPES].[BigInt] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'all_type_id' THEN [ALL_TYPES].[all_type_id] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'all_type_id' THEN [ALL_TYPES].[all_type_id] END END

	,CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'created_by' THEN [ALL_TYPES].[created_by] END END DESC
	,CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'created_by' THEN [ALL_TYPES].[created_by] END END
	,CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'created_date' THEN [ALL_TYPES].[created_date] END END DESC
	,CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'created_date' THEN [ALL_TYPES].[created_date] END END
	,CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'modified_by' THEN [ALL_TYPES].[modified_by] END END DESC
	,CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'modified_by' THEN [ALL_TYPES].[modified_by] END END
	,CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'modified_date' THEN [ALL_TYPES].[modified_date] END END DESC
	,CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'modified_date' THEN [ALL_TYPES].[modified_date] END END
-- set @paging_Count based on the rows moved in the previous statement
SET ROWCOUNT 0
SET @paging_Count = (
SELECT count(*)
FROM
[ALL_TYPES]
WHERE
((@xml is null) OR ([ALL_TYPES].[xml] LIKE @xml)) AND
((@varcharmax is null) OR ([ALL_TYPES].[varcharmax] LIKE @varcharmax)) AND
((@varchar is null) OR ([ALL_TYPES].[varchar] LIKE @varchar)) AND
((@uniqueidentifier is null) OR ([ALL_TYPES].[uniqueidentifier] = @uniqueidentifier)) AND
((@tinyint is null) OR ([ALL_TYPES].[tinyint] = @tinyint)) AND
((@time is null) OR ([ALL_TYPES].[time] LIKE @time)) AND
((@sql_variant is null) OR ([ALL_TYPES].[sql_variant] LIKE @sql_variant)) AND
((@smallmoney is null) OR ([ALL_TYPES].[smallmoney] = @smallmoney)) AND
((@smallint is null) OR ([ALL_TYPES].[smallint] = @smallint)) AND
((@smalldatetime is null) OR ([ALL_TYPES].[smalldatetime] = @smalldatetime)) AND
((@real is null) OR ([ALL_TYPES].[real] = @real)) AND
((@nvarcharmax is null) OR ([ALL_TYPES].[nvarcharmax] LIKE @nvarcharmax)) AND
((@nvarchar is null) OR ([ALL_TYPES].[nvarchar] LIKE @nvarchar)) AND
((@numeric is null) OR ([ALL_TYPES].[numeric] = @numeric)) AND
((@nchar is null) OR ([ALL_TYPES].[nchar] LIKE @nchar)) AND
((@int_test is null) OR ([ALL_TYPES].[int_test] = @int_test)) AND
((@hierarchyid is null) OR ([ALL_TYPES].[hierarchyid] LIKE @hierarchyid)) AND
((@geometry is null) OR ([ALL_TYPES].[geometry] LIKE @geometry)) AND
((@geography is null) OR ([ALL_TYPES].[geography] LIKE @geography)) AND
((@float_test is null) OR ([ALL_TYPES].[float_test] = @float_test)) AND
((@decimal_test is null) OR ([ALL_TYPES].[decimal_test] = @decimal_test)) AND
((@datetimeoffset is null) OR ([ALL_TYPES].[datetimeoffset] LIKE @datetimeoffset)) AND
((@datetime2 is null) OR ([ALL_TYPES].[datetime2] LIKE @datetime2)) AND
((@datetime is null) OR ([ALL_TYPES].[datetime] = @datetime)) AND
((@date_test is null) OR ([ALL_TYPES].[date_test] LIKE @date_test)) AND
((@computedPersisted is null) OR ([ALL_TYPES].[computedPersisted] LIKE @computedPersisted)) AND
((@computedNotPersisted is null) OR ([ALL_TYPES].[computedNotPersisted] LIKE @computedNotPersisted)) AND
((@char_test is null) OR ([ALL_TYPES].[char_test] LIKE @char_test)) AND
((@bit is null) OR ([ALL_TYPES].[bit] = @bit)) AND
((@BigInt is null) OR ([ALL_TYPES].[BigInt] = @BigInt)) AND
((@all_type_id is null) OR ([ALL_TYPES].[all_type_id] = @all_type_id))
)

-- remove top x values from the temp table based upon the specific page requested
SET @total__ivqatedr = (@paging_RecordsperPage * @paging_PageIndex) - @paging_RecordsperPage
IF (@total__ivqatedr <> 0) AND (@paging_PageIndex <> -1)
BEGIN
	SET ROWCOUNT @total__ivqatedr
	DELETE FROM #tmpTable
END

-- return the number of rows requested as the page size
IF (@paging_PageIndex <> -1)
BEGIN
SET ROWCOUNT @paging_RecordsperPage
END
SELECT
	[ALL_TYPES].[xml],
	[ALL_TYPES].[varcharmax],
	[ALL_TYPES].[varchar],
	[ALL_TYPES].[varbinarymax],
	[ALL_TYPES].[varbinary],
	[ALL_TYPES].[uniqueidentifier],
	[ALL_TYPES].[tinyint],
	[ALL_TYPES].[time],
	[ALL_TYPES].[text],
	[ALL_TYPES].[sql_variant],
	[ALL_TYPES].[smallmoney],
	[ALL_TYPES].[smallint],
	[ALL_TYPES].[smalldatetime],
	[ALL_TYPES].[real],
	[ALL_TYPES].[nvarcharmax],
	[ALL_TYPES].[nvarchar],
	[ALL_TYPES].[numeric],
	[ALL_TYPES].[ntext],
	[ALL_TYPES].[nchar],
	[ALL_TYPES].[money],
	[ALL_TYPES].[int_test],
	[ALL_TYPES].[image],
	[ALL_TYPES].[hierarchyid],
	[ALL_TYPES].[geometry],
	[ALL_TYPES].[geography],
	[ALL_TYPES].[float_test],
	[ALL_TYPES].[decimal_test],
	[ALL_TYPES].[datetimeoffset],
	[ALL_TYPES].[datetime2],
	[ALL_TYPES].[datetime],
	[ALL_TYPES].[date_test],
	[ALL_TYPES].[computedpersisted],
	[ALL_TYPES].[computednotpersisted],
	[ALL_TYPES].[char_test],
	[ALL_TYPES].[bit],
	[ALL_TYPES].[binary],
	[ALL_TYPES].[bigint],
	[ALL_TYPES].[all_type_id],
	[ALL_TYPES].[created_by],
	[ALL_TYPES].[created_date],
	[ALL_TYPES].[modified_by],
	[ALL_TYPES].[modified_date],
	[ALL_TYPES].[time_stamp]
FROM
	[#tmpTable]
	INNER JOIN [ALL_TYPES] ON #tmpTable.[all_type_id] = [ALL_TYPES].[all_type_id]
ORDER BY
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'xml' THEN [ALL_TYPES].[xml] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'xml' THEN [ALL_TYPES].[xml] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'varcharmax' THEN [ALL_TYPES].[varcharmax] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'varcharmax' THEN [ALL_TYPES].[varcharmax] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'varchar' THEN [ALL_TYPES].[varchar] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'varchar' THEN [ALL_TYPES].[varchar] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'uniqueidentifier' THEN [ALL_TYPES].[uniqueidentifier] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'uniqueidentifier' THEN [ALL_TYPES].[uniqueidentifier] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'tinyint' THEN [ALL_TYPES].[tinyint] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'tinyint' THEN [ALL_TYPES].[tinyint] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'time' THEN [ALL_TYPES].[time] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'time' THEN [ALL_TYPES].[time] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'sql_variant' THEN [ALL_TYPES].[sql_variant] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'sql_variant' THEN [ALL_TYPES].[sql_variant] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'smallmoney' THEN [ALL_TYPES].[smallmoney] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'smallmoney' THEN [ALL_TYPES].[smallmoney] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'smallint' THEN [ALL_TYPES].[smallint] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'smallint' THEN [ALL_TYPES].[smallint] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'smalldatetime' THEN [ALL_TYPES].[smalldatetime] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'smalldatetime' THEN [ALL_TYPES].[smalldatetime] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'real' THEN [ALL_TYPES].[real] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'real' THEN [ALL_TYPES].[real] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'nvarcharmax' THEN [ALL_TYPES].[nvarcharmax] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'nvarcharmax' THEN [ALL_TYPES].[nvarcharmax] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'nvarchar' THEN [ALL_TYPES].[nvarchar] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'nvarchar' THEN [ALL_TYPES].[nvarchar] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'numeric' THEN [ALL_TYPES].[numeric] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'numeric' THEN [ALL_TYPES].[numeric] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'nchar' THEN [ALL_TYPES].[nchar] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'nchar' THEN [ALL_TYPES].[nchar] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'int_test' THEN [ALL_TYPES].[int_test] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'int_test' THEN [ALL_TYPES].[int_test] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'hierarchyid' THEN [ALL_TYPES].[hierarchyid] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'hierarchyid' THEN [ALL_TYPES].[hierarchyid] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'geometry' THEN [ALL_TYPES].[geometry] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'geometry' THEN [ALL_TYPES].[geometry] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'geography' THEN [ALL_TYPES].[geography] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'geography' THEN [ALL_TYPES].[geography] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'float_test' THEN [ALL_TYPES].[float_test] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'float_test' THEN [ALL_TYPES].[float_test] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'decimal_test' THEN [ALL_TYPES].[decimal_test] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'decimal_test' THEN [ALL_TYPES].[decimal_test] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'datetimeoffset' THEN [ALL_TYPES].[datetimeoffset] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'datetimeoffset' THEN [ALL_TYPES].[datetimeoffset] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'datetime2' THEN [ALL_TYPES].[datetime2] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'datetime2' THEN [ALL_TYPES].[datetime2] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'datetime' THEN [ALL_TYPES].[datetime] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'datetime' THEN [ALL_TYPES].[datetime] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'date_test' THEN [ALL_TYPES].[date_test] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'date_test' THEN [ALL_TYPES].[date_test] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'computedPersisted' THEN [ALL_TYPES].[computedPersisted] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'computedPersisted' THEN [ALL_TYPES].[computedPersisted] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'computedNotPersisted' THEN [ALL_TYPES].[computedNotPersisted] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'computedNotPersisted' THEN [ALL_TYPES].[computedNotPersisted] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'char_test' THEN [ALL_TYPES].[char_test] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'char_test' THEN [ALL_TYPES].[char_test] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'bit' THEN [ALL_TYPES].[bit] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'bit' THEN [ALL_TYPES].[bit] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'BigInt' THEN [ALL_TYPES].[BigInt] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'BigInt' THEN [ALL_TYPES].[BigInt] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'all_type_id' THEN [ALL_TYPES].[all_type_id] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'all_type_id' THEN [ALL_TYPES].[all_type_id] END END

	,CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'created_by' THEN [ALL_TYPES].[created_by] END END DESC
	,CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'created_by' THEN [ALL_TYPES].[created_by] END END
	,CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'created_date' THEN [ALL_TYPES].[created_date] END END DESC
	,CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'created_date' THEN [ALL_TYPES].[created_date] END END
	,CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'modified_by' THEN [ALL_TYPES].[modified_by] END END DESC
	,CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'modified_by' THEN [ALL_TYPES].[modified_by] END END
	,CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'modified_date' THEN [ALL_TYPES].[modified_date] END END DESC
	,CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'modified_date' THEN [ALL_TYPES].[modified_date] END END
DROP TABLE #tmpTable

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[gen_AllTypesUpdate]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [dbo].[gen_AllTypesUpdate]
GO


SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

CREATE PROCEDURE [dbo].[gen_AllTypesUpdate]
(
	@xml VarChar(max),
	@varcharmax VarChar(max),
	@varchar VarChar(50),
	@varbinarymax VarBinary(max),
	@varbinary VarBinary(50),
	@uniqueidentifier UniqueIdentifier,
	@tinyint TinyInt,
	@time VarChar(5),
	@text Text,
	@sql_variant VarChar(max),
	@smallmoney SmallMoney,
	@smallint SmallInt,
	@smalldatetime SmallDateTime,
	@real Real,
	@nvarcharmax NVarChar(max),
	@nvarchar NVarChar(50),
	@numeric Decimal(18, 0),
	@ntext NText,
	@nchar NChar(10),
	@money Money,
	@int_test Int,
	@image Image,
	@hierarchyid VarChar(892),
	@geometry VarChar(max),
	@geography VarChar(max),
	@float_test Float,
	@decimal_test Decimal(18, 0),
	@datetimeoffset VarChar(10),
	@datetime2 VarChar(8),
	@datetime DateTime,
	@date_test VarChar(3),
	@char_test Char(10),
	@bit Bit,
	@binary Binary(50),
	@BigInt BigInt,
	@modified_by varchar (50),
	@modified_date datetime = null,
	@Original_all_type_id UniqueIdentifier,
	@Original_time_stamp timestamp

)
AS

IF (@modified_date IS NULL)
SET @modified_date = GetDate();

SET NOCOUNT OFF;
UPDATE 
[ALL_TYPES] 
SET
[BigInt] = @BigInt,
[binary] = @binary,
[bit] = @bit,
[char_test] = @char_test,
[date_test] = @date_test,
[datetime] = @datetime,
[datetime2] = @datetime2,
[datetimeoffset] = @datetimeoffset,
[decimal_test] = @decimal_test,
[float_test] = @float_test,
[geography] = @geography,
[geometry] = @geometry,
[hierarchyid] = @hierarchyid,
[image] = @image,
[int_test] = @int_test,
[money] = @money,
[nchar] = @nchar,
[ntext] = @ntext,
[numeric] = @numeric,
[nvarchar] = @nvarchar,
[nvarcharmax] = @nvarcharmax,
[real] = @real,
[smalldatetime] = @smalldatetime,
[smallint] = @smallint,
[smallmoney] = @smallmoney,
[sql_variant] = @sql_variant,
[text] = @text,
[time] = @time,
[tinyint] = @tinyint,
[uniqueidentifier] = @uniqueidentifier,
[varbinary] = @varbinary,
[varbinarymax] = @varbinarymax,
[varchar] = @varchar,
[varcharmax] = @varcharmax,
[xml] = @xml,
[modified_by] = @modified_by,
[modified_date] = @modified_date

WHERE
	[ALL_TYPES].[all_type_id] = @Original_all_type_id AND
	[ALL_TYPES].[time_stamp] = @Original_time_stamp


SELECT
	[ALL_TYPES].[xml],
	[ALL_TYPES].[varcharmax],
	[ALL_TYPES].[varchar],
	[ALL_TYPES].[varbinarymax],
	[ALL_TYPES].[varbinary],
	[ALL_TYPES].[uniqueidentifier],
	[ALL_TYPES].[tinyint],
	[ALL_TYPES].[time],
	[ALL_TYPES].[text],
	[ALL_TYPES].[sql_variant],
	[ALL_TYPES].[smallmoney],
	[ALL_TYPES].[smallint],
	[ALL_TYPES].[smalldatetime],
	[ALL_TYPES].[real],
	[ALL_TYPES].[nvarcharmax],
	[ALL_TYPES].[nvarchar],
	[ALL_TYPES].[numeric],
	[ALL_TYPES].[ntext],
	[ALL_TYPES].[nchar],
	[ALL_TYPES].[money],
	[ALL_TYPES].[int_test],
	[ALL_TYPES].[image],
	[ALL_TYPES].[hierarchyid],
	[ALL_TYPES].[geometry],
	[ALL_TYPES].[geography],
	[ALL_TYPES].[float_test],
	[ALL_TYPES].[decimal_test],
	[ALL_TYPES].[datetimeoffset],
	[ALL_TYPES].[datetime2],
	[ALL_TYPES].[datetime],
	[ALL_TYPES].[date_test],
	[ALL_TYPES].[computedpersisted],
	[ALL_TYPES].[computednotpersisted],
	[ALL_TYPES].[char_test],
	[ALL_TYPES].[bit],
	[ALL_TYPES].[binary],
	[ALL_TYPES].[bigint],
	[ALL_TYPES].[all_type_id],
	[ALL_TYPES].[created_by],
	[ALL_TYPES].[created_date],
	[ALL_TYPES].[modified_by],
	[ALL_TYPES].[modified_date],
	[ALL_TYPES].[time_stamp]
FROM 
[ALL_TYPES]
WHERE
	[ALL_TYPES].[all_type_id] = @Original_all_type_id AND
	@@RowCount > 0
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[gen_AllTypesSelectByCreatedDateRange]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [dbo].[gen_AllTypesSelectByCreatedDateRange]
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

CREATE PROCEDURE [dbo].[gen_AllTypesSelectByCreatedDateRange]
(
	@start_date datetime,
	@end_date datetime
)
AS

SET NOCOUNT ON;

SELECT
		[ALL_TYPES].[xml],
	[ALL_TYPES].[varcharmax],
	[ALL_TYPES].[varchar],
	[ALL_TYPES].[varbinarymax],
	[ALL_TYPES].[varbinary],
	[ALL_TYPES].[uniqueidentifier],
	[ALL_TYPES].[tinyint],
	[ALL_TYPES].[time],
	[ALL_TYPES].[text],
	[ALL_TYPES].[sql_variant],
	[ALL_TYPES].[smallmoney],
	[ALL_TYPES].[smallint],
	[ALL_TYPES].[smalldatetime],
	[ALL_TYPES].[real],
	[ALL_TYPES].[nvarcharmax],
	[ALL_TYPES].[nvarchar],
	[ALL_TYPES].[numeric],
	[ALL_TYPES].[ntext],
	[ALL_TYPES].[nchar],
	[ALL_TYPES].[money],
	[ALL_TYPES].[int_test],
	[ALL_TYPES].[image],
	[ALL_TYPES].[hierarchyid],
	[ALL_TYPES].[geometry],
	[ALL_TYPES].[geography],
	[ALL_TYPES].[float_test],
	[ALL_TYPES].[decimal_test],
	[ALL_TYPES].[datetimeoffset],
	[ALL_TYPES].[datetime2],
	[ALL_TYPES].[datetime],
	[ALL_TYPES].[date_test],
	[ALL_TYPES].[computedpersisted],
	[ALL_TYPES].[computednotpersisted],
	[ALL_TYPES].[char_test],
	[ALL_TYPES].[bit],
	[ALL_TYPES].[binary],
	[ALL_TYPES].[bigint],
	[ALL_TYPES].[all_type_id],
	[ALL_TYPES].[created_by],
	[ALL_TYPES].[created_date],
	[ALL_TYPES].[modified_by],
	[ALL_TYPES].[modified_date],
	[ALL_TYPES].[time_stamp]

FROM
[ALL_TYPES]
WHERE
((([ALL_TYPES].[created_date] IS NULL) AND (@start_date IS NULL)) OR (@start_date <= [ALL_TYPES].[created_date])) AND 
((([ALL_TYPES].[created_date] IS NULL) AND (@end_date IS NULL)) OR (@end_date >= [ALL_TYPES].[created_date]))
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[gen_AllTypesSelectByModifiedDateRange]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [dbo].[gen_AllTypesSelectByModifiedDateRange]
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

CREATE PROCEDURE [dbo].[gen_AllTypesSelectByModifiedDateRange]
(
	@start_date datetime,
	@end_date datetime
)
AS

SET NOCOUNT ON;

SELECT
		[ALL_TYPES].[xml],
	[ALL_TYPES].[varcharmax],
	[ALL_TYPES].[varchar],
	[ALL_TYPES].[varbinarymax],
	[ALL_TYPES].[varbinary],
	[ALL_TYPES].[uniqueidentifier],
	[ALL_TYPES].[tinyint],
	[ALL_TYPES].[time],
	[ALL_TYPES].[text],
	[ALL_TYPES].[sql_variant],
	[ALL_TYPES].[smallmoney],
	[ALL_TYPES].[smallint],
	[ALL_TYPES].[smalldatetime],
	[ALL_TYPES].[real],
	[ALL_TYPES].[nvarcharmax],
	[ALL_TYPES].[nvarchar],
	[ALL_TYPES].[numeric],
	[ALL_TYPES].[ntext],
	[ALL_TYPES].[nchar],
	[ALL_TYPES].[money],
	[ALL_TYPES].[int_test],
	[ALL_TYPES].[image],
	[ALL_TYPES].[hierarchyid],
	[ALL_TYPES].[geometry],
	[ALL_TYPES].[geography],
	[ALL_TYPES].[float_test],
	[ALL_TYPES].[decimal_test],
	[ALL_TYPES].[datetimeoffset],
	[ALL_TYPES].[datetime2],
	[ALL_TYPES].[datetime],
	[ALL_TYPES].[date_test],
	[ALL_TYPES].[computedpersisted],
	[ALL_TYPES].[computednotpersisted],
	[ALL_TYPES].[char_test],
	[ALL_TYPES].[bit],
	[ALL_TYPES].[binary],
	[ALL_TYPES].[bigint],
	[ALL_TYPES].[all_type_id],
	[ALL_TYPES].[created_by],
	[ALL_TYPES].[created_date],
	[ALL_TYPES].[modified_by],
	[ALL_TYPES].[modified_date],
	[ALL_TYPES].[time_stamp]

FROM
[ALL_TYPES]
WHERE
((([ALL_TYPES].[modified_date] IS NULL) AND (@start_date IS NULL)) OR (@start_date <= [ALL_TYPES].[modified_date])) AND 
((([ALL_TYPES].[modified_date] IS NULL) AND (@end_date IS NULL)) OR (@end_date >= [ALL_TYPES].[modified_date]))
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[gen_AllTypesSelectBySearchOr]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [dbo].[gen_AllTypesSelectBySearchOr]
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

CREATE PROCEDURE [dbo].[gen_AllTypesSelectBySearchOr]
(
	@xml VarChar(max) = null, 
	@varcharmax VarChar(max) = null, 
	@varchar VarChar(50) = null, 
	@uniqueidentifier UniqueIdentifier = null, 
	@tinyint TinyInt = null, 
	@time VarChar(5) = null, 
	@sql_variant VarChar(max) = null, 
	@smallmoney SmallMoney = null, 
	@smallint SmallInt = null, 
	@smalldatetime SmallDateTime = null, 
	@real Real = null, 
	@nvarcharmax NVarChar(max) = null, 
	@nvarchar NVarChar(50) = null, 
	@numeric Decimal = null, 
	@nchar NChar(10) = null, 
	@int_test Int = null, 
	@hierarchyid VarChar(892) = null, 
	@geometry VarChar(max) = null, 
	@geography VarChar(max) = null, 
	@float_test Float = null, 
	@decimal_test Decimal = null, 
	@datetimeoffset VarChar(10) = null, 
	@datetime2 VarChar(8) = null, 
	@datetime DateTime = null, 
	@date_test VarChar(3) = null, 
	@computedPersisted VarChar(1) = null, 
	@computedNotPersisted VarChar(1) = null, 
	@char_test Char(10) = null, 
	@bit Bit = null, 
	@BigInt BigInt = null, 
	@all_type_id UniqueIdentifier = null, 
	@paging_PageIndex int = -1, -- page number selected by the user
	@paging_RecordsperPage int = -1, -- number of items on the page
	@paging_OrderByColumn varchar(100) = '', -- name of column to order things by
	@paging_Ascending bit = 1, -- order column ascending or descending
	@paging_Count int out -- number of items in the collection
)
AS

CREATE TABLE #tmpTable 
(
	[all_type_id] UniqueIdentifier
)

DECLARE @total__ivqatedr int
DECLARE @orderByColumnIndex int
-- remove top x values from the temp table based upon the specific page requested
SET @total__ivqatedr = (@paging_RecordsperPage * @paging_PageIndex)
IF (@total__ivqatedr <> 0) AND (@paging_PageIndex <> -1)
BEGIN
	SET ROWCOUNT @total__ivqatedr
END
INSERT INTO #tmpTable
(
	[all_type_id]
)
SELECT
	[ALL_TYPES].[all_type_id]
FROM
[ALL_TYPES]
WHERE
((@xml is null) OR ([ALL_TYPES].[xml] LIKE @xml)) OR
((@varcharmax is null) OR ([ALL_TYPES].[varcharmax] LIKE @varcharmax)) OR
((@varchar is null) OR ([ALL_TYPES].[varchar] LIKE @varchar)) OR
((@uniqueidentifier is null) OR ([ALL_TYPES].[uniqueidentifier] = @uniqueidentifier)) OR
((@tinyint is null) OR ([ALL_TYPES].[tinyint] = @tinyint)) OR
((@time is null) OR ([ALL_TYPES].[time] LIKE @time)) OR
((@sql_variant is null) OR ([ALL_TYPES].[sql_variant] LIKE @sql_variant)) OR
((@smallmoney is null) OR ([ALL_TYPES].[smallmoney] = @smallmoney)) OR
((@smallint is null) OR ([ALL_TYPES].[smallint] = @smallint)) OR
((@smalldatetime is null) OR ([ALL_TYPES].[smalldatetime] = @smalldatetime)) OR
((@real is null) OR ([ALL_TYPES].[real] = @real)) OR
((@nvarcharmax is null) OR ([ALL_TYPES].[nvarcharmax] LIKE @nvarcharmax)) OR
((@nvarchar is null) OR ([ALL_TYPES].[nvarchar] LIKE @nvarchar)) OR
((@numeric is null) OR ([ALL_TYPES].[numeric] = @numeric)) OR
((@nchar is null) OR ([ALL_TYPES].[nchar] LIKE @nchar)) OR
((@int_test is null) OR ([ALL_TYPES].[int_test] = @int_test)) OR
((@hierarchyid is null) OR ([ALL_TYPES].[hierarchyid] LIKE @hierarchyid)) OR
((@geometry is null) OR ([ALL_TYPES].[geometry] LIKE @geometry)) OR
((@geography is null) OR ([ALL_TYPES].[geography] LIKE @geography)) OR
((@float_test is null) OR ([ALL_TYPES].[float_test] = @float_test)) OR
((@decimal_test is null) OR ([ALL_TYPES].[decimal_test] = @decimal_test)) OR
((@datetimeoffset is null) OR ([ALL_TYPES].[datetimeoffset] LIKE @datetimeoffset)) OR
((@datetime2 is null) OR ([ALL_TYPES].[datetime2] LIKE @datetime2)) OR
((@datetime is null) OR ([ALL_TYPES].[datetime] = @datetime)) OR
((@date_test is null) OR ([ALL_TYPES].[date_test] LIKE @date_test)) OR
((@computedPersisted is null) OR ([ALL_TYPES].[computedPersisted] LIKE @computedPersisted)) OR
((@computedNotPersisted is null) OR ([ALL_TYPES].[computedNotPersisted] LIKE @computedNotPersisted)) OR
((@char_test is null) OR ([ALL_TYPES].[char_test] LIKE @char_test)) OR
((@bit is null) OR ([ALL_TYPES].[bit] = @bit)) OR
((@BigInt is null) OR ([ALL_TYPES].[BigInt] = @BigInt)) OR
((@all_type_id is null) OR ([ALL_TYPES].[all_type_id] = @all_type_id))
ORDER BY
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'xml' THEN [ALL_TYPES].[xml] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'xml' THEN [ALL_TYPES].[xml] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'varcharmax' THEN [ALL_TYPES].[varcharmax] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'varcharmax' THEN [ALL_TYPES].[varcharmax] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'varchar' THEN [ALL_TYPES].[varchar] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'varchar' THEN [ALL_TYPES].[varchar] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'uniqueidentifier' THEN [ALL_TYPES].[uniqueidentifier] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'uniqueidentifier' THEN [ALL_TYPES].[uniqueidentifier] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'tinyint' THEN [ALL_TYPES].[tinyint] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'tinyint' THEN [ALL_TYPES].[tinyint] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'time' THEN [ALL_TYPES].[time] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'time' THEN [ALL_TYPES].[time] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'sql_variant' THEN [ALL_TYPES].[sql_variant] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'sql_variant' THEN [ALL_TYPES].[sql_variant] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'smallmoney' THEN [ALL_TYPES].[smallmoney] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'smallmoney' THEN [ALL_TYPES].[smallmoney] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'smallint' THEN [ALL_TYPES].[smallint] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'smallint' THEN [ALL_TYPES].[smallint] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'smalldatetime' THEN [ALL_TYPES].[smalldatetime] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'smalldatetime' THEN [ALL_TYPES].[smalldatetime] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'real' THEN [ALL_TYPES].[real] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'real' THEN [ALL_TYPES].[real] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'nvarcharmax' THEN [ALL_TYPES].[nvarcharmax] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'nvarcharmax' THEN [ALL_TYPES].[nvarcharmax] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'nvarchar' THEN [ALL_TYPES].[nvarchar] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'nvarchar' THEN [ALL_TYPES].[nvarchar] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'numeric' THEN [ALL_TYPES].[numeric] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'numeric' THEN [ALL_TYPES].[numeric] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'nchar' THEN [ALL_TYPES].[nchar] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'nchar' THEN [ALL_TYPES].[nchar] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'int_test' THEN [ALL_TYPES].[int_test] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'int_test' THEN [ALL_TYPES].[int_test] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'hierarchyid' THEN [ALL_TYPES].[hierarchyid] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'hierarchyid' THEN [ALL_TYPES].[hierarchyid] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'geometry' THEN [ALL_TYPES].[geometry] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'geometry' THEN [ALL_TYPES].[geometry] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'geography' THEN [ALL_TYPES].[geography] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'geography' THEN [ALL_TYPES].[geography] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'float_test' THEN [ALL_TYPES].[float_test] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'float_test' THEN [ALL_TYPES].[float_test] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'decimal_test' THEN [ALL_TYPES].[decimal_test] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'decimal_test' THEN [ALL_TYPES].[decimal_test] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'datetimeoffset' THEN [ALL_TYPES].[datetimeoffset] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'datetimeoffset' THEN [ALL_TYPES].[datetimeoffset] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'datetime2' THEN [ALL_TYPES].[datetime2] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'datetime2' THEN [ALL_TYPES].[datetime2] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'datetime' THEN [ALL_TYPES].[datetime] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'datetime' THEN [ALL_TYPES].[datetime] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'date_test' THEN [ALL_TYPES].[date_test] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'date_test' THEN [ALL_TYPES].[date_test] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'computedPersisted' THEN [ALL_TYPES].[computedPersisted] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'computedPersisted' THEN [ALL_TYPES].[computedPersisted] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'computedNotPersisted' THEN [ALL_TYPES].[computedNotPersisted] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'computedNotPersisted' THEN [ALL_TYPES].[computedNotPersisted] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'char_test' THEN [ALL_TYPES].[char_test] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'char_test' THEN [ALL_TYPES].[char_test] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'bit' THEN [ALL_TYPES].[bit] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'bit' THEN [ALL_TYPES].[bit] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'BigInt' THEN [ALL_TYPES].[BigInt] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'BigInt' THEN [ALL_TYPES].[BigInt] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'all_type_id' THEN [ALL_TYPES].[all_type_id] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'all_type_id' THEN [ALL_TYPES].[all_type_id] END END

	,CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'created_by' THEN [ALL_TYPES].[created_by] END END DESC
	,CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'created_by' THEN [ALL_TYPES].[created_by] END END
	,CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'created_date' THEN [ALL_TYPES].[created_date] END END DESC
	,CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'created_date' THEN [ALL_TYPES].[created_date] END END
	,CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'modified_by' THEN [ALL_TYPES].[modified_by] END END DESC
	,CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'modified_by' THEN [ALL_TYPES].[modified_by] END END
	,CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'modified_date' THEN [ALL_TYPES].[modified_date] END END DESC
	,CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'modified_date' THEN [ALL_TYPES].[modified_date] END END
-- set @paging_Count based on the rows moved in the previous statement
SET ROWCOUNT 0
SET @paging_Count = (
SELECT count(*)
FROM
[ALL_TYPES]
WHERE
((@xml is null) OR ([ALL_TYPES].[xml] LIKE @xml)) OR
((@varcharmax is null) OR ([ALL_TYPES].[varcharmax] LIKE @varcharmax)) OR
((@varchar is null) OR ([ALL_TYPES].[varchar] LIKE @varchar)) OR
((@uniqueidentifier is null) OR ([ALL_TYPES].[uniqueidentifier] = @uniqueidentifier)) OR
((@tinyint is null) OR ([ALL_TYPES].[tinyint] = @tinyint)) OR
((@time is null) OR ([ALL_TYPES].[time] LIKE @time)) OR
((@sql_variant is null) OR ([ALL_TYPES].[sql_variant] LIKE @sql_variant)) OR
((@smallmoney is null) OR ([ALL_TYPES].[smallmoney] = @smallmoney)) OR
((@smallint is null) OR ([ALL_TYPES].[smallint] = @smallint)) OR
((@smalldatetime is null) OR ([ALL_TYPES].[smalldatetime] = @smalldatetime)) OR
((@real is null) OR ([ALL_TYPES].[real] = @real)) OR
((@nvarcharmax is null) OR ([ALL_TYPES].[nvarcharmax] LIKE @nvarcharmax)) OR
((@nvarchar is null) OR ([ALL_TYPES].[nvarchar] LIKE @nvarchar)) OR
((@numeric is null) OR ([ALL_TYPES].[numeric] = @numeric)) OR
((@nchar is null) OR ([ALL_TYPES].[nchar] LIKE @nchar)) OR
((@int_test is null) OR ([ALL_TYPES].[int_test] = @int_test)) OR
((@hierarchyid is null) OR ([ALL_TYPES].[hierarchyid] LIKE @hierarchyid)) OR
((@geometry is null) OR ([ALL_TYPES].[geometry] LIKE @geometry)) OR
((@geography is null) OR ([ALL_TYPES].[geography] LIKE @geography)) OR
((@float_test is null) OR ([ALL_TYPES].[float_test] = @float_test)) OR
((@decimal_test is null) OR ([ALL_TYPES].[decimal_test] = @decimal_test)) OR
((@datetimeoffset is null) OR ([ALL_TYPES].[datetimeoffset] LIKE @datetimeoffset)) OR
((@datetime2 is null) OR ([ALL_TYPES].[datetime2] LIKE @datetime2)) OR
((@datetime is null) OR ([ALL_TYPES].[datetime] = @datetime)) OR
((@date_test is null) OR ([ALL_TYPES].[date_test] LIKE @date_test)) OR
((@computedPersisted is null) OR ([ALL_TYPES].[computedPersisted] LIKE @computedPersisted)) OR
((@computedNotPersisted is null) OR ([ALL_TYPES].[computedNotPersisted] LIKE @computedNotPersisted)) OR
((@char_test is null) OR ([ALL_TYPES].[char_test] LIKE @char_test)) OR
((@bit is null) OR ([ALL_TYPES].[bit] = @bit)) OR
((@BigInt is null) OR ([ALL_TYPES].[BigInt] = @BigInt)) OR
((@all_type_id is null) OR ([ALL_TYPES].[all_type_id] = @all_type_id))
)

-- remove top x values from the temp table based upon the specific page requested
SET @total__ivqatedr = (@paging_RecordsperPage * @paging_PageIndex) - @paging_RecordsperPage
IF (@total__ivqatedr <> 0) AND (@paging_PageIndex <> -1)
BEGIN
	SET ROWCOUNT @total__ivqatedr
	DELETE FROM #tmpTable
END

-- return the number of rows requested as the page size
IF (@paging_PageIndex <> -1)
BEGIN
SET ROWCOUNT @paging_RecordsperPage
END
SELECT
	[ALL_TYPES].[xml],
	[ALL_TYPES].[varcharmax],
	[ALL_TYPES].[varchar],
	[ALL_TYPES].[varbinarymax],
	[ALL_TYPES].[varbinary],
	[ALL_TYPES].[uniqueidentifier],
	[ALL_TYPES].[tinyint],
	[ALL_TYPES].[time],
	[ALL_TYPES].[text],
	[ALL_TYPES].[sql_variant],
	[ALL_TYPES].[smallmoney],
	[ALL_TYPES].[smallint],
	[ALL_TYPES].[smalldatetime],
	[ALL_TYPES].[real],
	[ALL_TYPES].[nvarcharmax],
	[ALL_TYPES].[nvarchar],
	[ALL_TYPES].[numeric],
	[ALL_TYPES].[ntext],
	[ALL_TYPES].[nchar],
	[ALL_TYPES].[money],
	[ALL_TYPES].[int_test],
	[ALL_TYPES].[image],
	[ALL_TYPES].[hierarchyid],
	[ALL_TYPES].[geometry],
	[ALL_TYPES].[geography],
	[ALL_TYPES].[float_test],
	[ALL_TYPES].[decimal_test],
	[ALL_TYPES].[datetimeoffset],
	[ALL_TYPES].[datetime2],
	[ALL_TYPES].[datetime],
	[ALL_TYPES].[date_test],
	[ALL_TYPES].[computedpersisted],
	[ALL_TYPES].[computednotpersisted],
	[ALL_TYPES].[char_test],
	[ALL_TYPES].[bit],
	[ALL_TYPES].[binary],
	[ALL_TYPES].[bigint],
	[ALL_TYPES].[all_type_id],
	[ALL_TYPES].[created_by],
	[ALL_TYPES].[created_date],
	[ALL_TYPES].[modified_by],
	[ALL_TYPES].[modified_date],
	[ALL_TYPES].[time_stamp]
FROM
	[#tmpTable]
	INNER JOIN [ALL_TYPES] ON #tmpTable.[all_type_id] = [ALL_TYPES].[all_type_id]
ORDER BY
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'xml' THEN [ALL_TYPES].[xml] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'xml' THEN [ALL_TYPES].[xml] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'varcharmax' THEN [ALL_TYPES].[varcharmax] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'varcharmax' THEN [ALL_TYPES].[varcharmax] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'varchar' THEN [ALL_TYPES].[varchar] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'varchar' THEN [ALL_TYPES].[varchar] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'uniqueidentifier' THEN [ALL_TYPES].[uniqueidentifier] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'uniqueidentifier' THEN [ALL_TYPES].[uniqueidentifier] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'tinyint' THEN [ALL_TYPES].[tinyint] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'tinyint' THEN [ALL_TYPES].[tinyint] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'time' THEN [ALL_TYPES].[time] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'time' THEN [ALL_TYPES].[time] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'sql_variant' THEN [ALL_TYPES].[sql_variant] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'sql_variant' THEN [ALL_TYPES].[sql_variant] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'smallmoney' THEN [ALL_TYPES].[smallmoney] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'smallmoney' THEN [ALL_TYPES].[smallmoney] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'smallint' THEN [ALL_TYPES].[smallint] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'smallint' THEN [ALL_TYPES].[smallint] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'smalldatetime' THEN [ALL_TYPES].[smalldatetime] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'smalldatetime' THEN [ALL_TYPES].[smalldatetime] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'real' THEN [ALL_TYPES].[real] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'real' THEN [ALL_TYPES].[real] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'nvarcharmax' THEN [ALL_TYPES].[nvarcharmax] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'nvarcharmax' THEN [ALL_TYPES].[nvarcharmax] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'nvarchar' THEN [ALL_TYPES].[nvarchar] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'nvarchar' THEN [ALL_TYPES].[nvarchar] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'numeric' THEN [ALL_TYPES].[numeric] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'numeric' THEN [ALL_TYPES].[numeric] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'nchar' THEN [ALL_TYPES].[nchar] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'nchar' THEN [ALL_TYPES].[nchar] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'int_test' THEN [ALL_TYPES].[int_test] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'int_test' THEN [ALL_TYPES].[int_test] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'hierarchyid' THEN [ALL_TYPES].[hierarchyid] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'hierarchyid' THEN [ALL_TYPES].[hierarchyid] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'geometry' THEN [ALL_TYPES].[geometry] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'geometry' THEN [ALL_TYPES].[geometry] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'geography' THEN [ALL_TYPES].[geography] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'geography' THEN [ALL_TYPES].[geography] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'float_test' THEN [ALL_TYPES].[float_test] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'float_test' THEN [ALL_TYPES].[float_test] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'decimal_test' THEN [ALL_TYPES].[decimal_test] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'decimal_test' THEN [ALL_TYPES].[decimal_test] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'datetimeoffset' THEN [ALL_TYPES].[datetimeoffset] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'datetimeoffset' THEN [ALL_TYPES].[datetimeoffset] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'datetime2' THEN [ALL_TYPES].[datetime2] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'datetime2' THEN [ALL_TYPES].[datetime2] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'datetime' THEN [ALL_TYPES].[datetime] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'datetime' THEN [ALL_TYPES].[datetime] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'date_test' THEN [ALL_TYPES].[date_test] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'date_test' THEN [ALL_TYPES].[date_test] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'computedPersisted' THEN [ALL_TYPES].[computedPersisted] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'computedPersisted' THEN [ALL_TYPES].[computedPersisted] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'computedNotPersisted' THEN [ALL_TYPES].[computedNotPersisted] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'computedNotPersisted' THEN [ALL_TYPES].[computedNotPersisted] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'char_test' THEN [ALL_TYPES].[char_test] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'char_test' THEN [ALL_TYPES].[char_test] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'bit' THEN [ALL_TYPES].[bit] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'bit' THEN [ALL_TYPES].[bit] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'BigInt' THEN [ALL_TYPES].[BigInt] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'BigInt' THEN [ALL_TYPES].[BigInt] END END, 
	CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'all_type_id' THEN [ALL_TYPES].[all_type_id] END END DESC, 
	CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'all_type_id' THEN [ALL_TYPES].[all_type_id] END END

	,CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'created_by' THEN [ALL_TYPES].[created_by] END END DESC
	,CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'created_by' THEN [ALL_TYPES].[created_by] END END
	,CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'created_date' THEN [ALL_TYPES].[created_date] END END DESC
	,CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'created_date' THEN [ALL_TYPES].[created_date] END END
	,CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'modified_by' THEN [ALL_TYPES].[modified_by] END END DESC
	,CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'modified_by' THEN [ALL_TYPES].[modified_by] END END
	,CASE @paging_Ascending WHEN 0 THEN CASE @paging_OrderByColumn WHEN 'modified_date' THEN [ALL_TYPES].[modified_date] END END DESC
	,CASE @paging_Ascending WHEN 1 THEN CASE @paging_OrderByColumn WHEN 'modified_date' THEN [ALL_TYPES].[modified_date] END END
DROP TABLE #tmpTable

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[gen_AllTypesSelect]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [dbo].[gen_AllTypesSelect]
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

CREATE PROCEDURE [dbo].[gen_AllTypesSelect]
AS

SET NOCOUNT ON;

SELECT
		[ALL_TYPES].[xml],
	[ALL_TYPES].[varcharmax],
	[ALL_TYPES].[varchar],
	[ALL_TYPES].[varbinarymax],
	[ALL_TYPES].[varbinary],
	[ALL_TYPES].[uniqueidentifier],
	[ALL_TYPES].[tinyint],
	[ALL_TYPES].[time],
	[ALL_TYPES].[text],
	[ALL_TYPES].[sql_variant],
	[ALL_TYPES].[smallmoney],
	[ALL_TYPES].[smallint],
	[ALL_TYPES].[smalldatetime],
	[ALL_TYPES].[real],
	[ALL_TYPES].[nvarcharmax],
	[ALL_TYPES].[nvarchar],
	[ALL_TYPES].[numeric],
	[ALL_TYPES].[ntext],
	[ALL_TYPES].[nchar],
	[ALL_TYPES].[money],
	[ALL_TYPES].[int_test],
	[ALL_TYPES].[image],
	[ALL_TYPES].[hierarchyid],
	[ALL_TYPES].[geometry],
	[ALL_TYPES].[geography],
	[ALL_TYPES].[float_test],
	[ALL_TYPES].[decimal_test],
	[ALL_TYPES].[datetimeoffset],
	[ALL_TYPES].[datetime2],
	[ALL_TYPES].[datetime],
	[ALL_TYPES].[date_test],
	[ALL_TYPES].[computedpersisted],
	[ALL_TYPES].[computednotpersisted],
	[ALL_TYPES].[char_test],
	[ALL_TYPES].[bit],
	[ALL_TYPES].[binary],
	[ALL_TYPES].[bigint],
	[ALL_TYPES].[all_type_id],
	[ALL_TYPES].[created_by],
	[ALL_TYPES].[created_date],
	[ALL_TYPES].[modified_by],
	[ALL_TYPES].[modified_date],
	[ALL_TYPES].[time_stamp]

FROM 
[ALL_TYPES]
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

